package com.cn.dao;


import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;


import com.cn.entity.Leibie;


public class LeibieDao {
	public static SessionFactory sessionFactory;
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	Session session;
	
	 public void addLeibie(Leibie lb){
		   
		   session=sessionFactory.openSession();
		   Transaction tr=session.beginTransaction();
		   session.save(lb);
		   tr.commit();
		   session.close();
	 }
	 public List<Leibie> selectLeibies(){
		 
		 session=sessionFactory.openSession();
		 
		 String hql="from Leibie";
		 
		 Query query=session.createQuery(hql);
		 
		 List<Leibie> list=query.list();		
		 
		 for (int i=0;i<list.size();i++) {
			 Leibie leibie=list.get(i);
			 
		System.out.print(leibie.getLeibie()+"|"+leibie.getLeibieid()+"|");	 
		System.out.println("");
		 }
		 return list;
	 }
	 
	 
	 
 public Leibie selectLeibie(String leibie){
		 Leibie lb=null;
		 session=sessionFactory.openSession();
		 
		 String hql="from Leibie where leibie=?";
		 
		 Query query=session.createQuery(hql);
		 query.setString(0, leibie);
		 List<Leibie> list=query.list();
		 
		 if(list.size()>0){lb=list.get(0);  }
		 
		 return lb;
	 }
	 
	 
	 
	 


}
